<template>
  <view>
    <view style="background-color: #F60;position: fixed;left: 0;width: 100%; top:0;z-index: 1;">
      <bar></bar>
      <view class="gui-flex gui-nowrap gui-rows gui-align-items-center">

        <view class="gui-padding" style="padding-top: 0rpx;padding-right: 5rpx;" @click="back">
          <text class="gui-icons gui-color-white gui-h6">
            &#xe600;
          </text>
        </view>
        <view class="gui-padding gui-flex1" style="padding-top: 0;">
          <gui-search @inputting="inputting" @confirm="confirm"></gui-search>
        </view>
        <gui-mp-navigation-spacing></gui-mp-navigation-spacing>
      </view>
    </view>

    <view>
      <bar></bar>
      <view style="height: 80rpx;">

      </view>
    </view>

    <view class="gui-margin-top gui-padding-x gui-flex gui-row gui-wrap gui-space-between">

      <product-list-item v-for="item in products" :item="item">

      </product-list-item>
    </view>

  </view>
</template>

<script>
  // import bar from "@/pages/com/bar";
  import productListItem from "@/pages/product/product-list-item"

  export default {
    components: {
      // bar,
      productListItem
    },
    data() {
      return {
        products: []
      }
    },
    onLoad() {
      var skeywords = uni.getStorageSync("skeywords");
      console.log("识别到", skeywords)

      if (skeywords) {

        uni.removeStorageSync("skeywords");

        var self = this;
        uni.gRequest.get("product/list", {
          keywords: skeywords
        }).then(result => {
          result.rows.forEach(x => {
            x.product_avater = uni.gRequest.server.replace('/app/', '') + x.product_avater;
          })
          self.products = result.rows;
        });

      }

    },
    methods: {
      back() {
        uni.navigateBack();
      },
      inputting: function(e) {
        console.log(e);
      },
      // 监听提交
      confirm: function(e) {

        console.log(e)

        var self = this;
        uni.gRequest.get("product/list", {
          product_name: e
        }).then(result => {
          result.rows.forEach(x => {
            x.product_avater = uni.gRequest.server.replace('/app/', '') + x.product_avater;
          })
          self.products = result.rows;
        });
      },
    }
  }
</script>

<style>

</style>
